package com.bci.pwtz.common.util;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class SHA256Cryptor 
{
	public static String sha256Encrypt(String input)
	{
		return encrypt(input,"SHA-256");
	}
	
	static String encrypt(String input,String Algorithm)
	{
		String result = "";
        try 
        {
            MessageDigest md = MessageDigest.getInstance(Algorithm);
            md.update(input.getBytes());
            byte b[] = md.digest();
            int i;
            StringBuffer buf = new StringBuffer("");
            for (int offset = 0; offset < b.length; offset++) {
                    i = b[offset];
                    if (i < 0)
                            i += 256;
                    if (i < 16)
                            buf.append("0");
                    buf.append(Integer.toHexString(i));
            }
            result = buf.toString();
               
        } catch (NoSuchAlgorithmException e) {
                e.printStackTrace();
        }
        return result;
	}
}
